%GLOBAL CWD; %LET CWD = %SUBSTR(%SYSGET(SAS_EXECFILEPATH), 1, %EVAL(%LENGTH(%SYSGET(SAS_EXECFILEPATH)) - %LENGTH(%SYSGET(SAS_EXECFILENAME)) - 1));
%INCLUDE "&CWD\TOOLS.SAS";

/* SET ELI & CLUSTER */
%LET ELI = FL011;
%LET CLUSTER = 01;

/* IDENTIFYING HANDLE */
%LET COM = &ELI._&CLUSTER.;

/* ITEM-SPECIFIC RIGHT HAND SIDE VARIABLES */
%LET RHS = 
    B1 B2 B3 B4 D1 D2 D3 D4 D5 E99SP F99SP G1 G2 H1 MNAMT MNAMTSQ 
    ;

%LET STYR = 0201;
%LET FIRSTPER = 20&STYR.;
%LET LASTPER = 200709;
%LET STDUM = D&STYR.;
%LET RHYRS = D0202 -- D0709;

%LET NSPER = %COUNTMONTHS(&FIRSTPER, &LASTPER);
%LET NVEC = %EVAL(&NSPER + %COUNTWORDS(&RHS));

/* DEFINE ITEM-SPECIFIC PRICE EDITS */
%MACRO EDITS;
    IF A="A1";
    IF FULLSAMP_EFFPR_WOTX>3 THEN DELETE;  *OUTLIERS REMOVAL;
%MEND;

/* DEFINE ITEM-SPECIFIC DUMMIES */
%MACRO VARS;
    
    B1=(B="B1"); B2=(B="B2"); B3=(B="B3"); B4=(B="B4");
    B99SP=(B="B99"); 
    ARRAY BARRAY (5) B1-B4 B99SP;
    DO COUNT=1 TO 5;
        IF B="" THEN BARRAY(COUNT)=.;
    END;

    D1=(D="D1"); D2=(D="D2"); D3=(D="D3"); D4=(D="D4"); D5=(D="D5");
    D99SP=(D="D99"); 
    ARRAY DARRAY (6) D1-D5 D99SP;
    DO COUNT=1 TO 6;
        IF D="" THEN DARRAY(COUNT)=.;
    END;

    E99SP=(E="E99"); 
    F99SP=(F="F99"); 

    G1=(G="G1"); G2=(G="G2");G3=(G="G3");  
    ARRAY GARRAY (3) G1-G3;
    DO COUNT=1 TO 3;
        IF G="" THEN GARRAY(COUNT)=.;
    END;

    H1=(H="H1");  
    H99SP=(H="H99");
    ARRAY HARRAY (2) H1 H99SP;
    DO COUNT=1 TO 2;
        IF H="" THEN HARRAY(COUNT)=.;
    END;

    *ELIMINATE QUOTES WITH MISSING SPEC VARIABLES;
    *INCLUDE APPROPRIATE LIST OF SPEC VARIABLES HERE AND ELSEWHERE;
    *MODIFY SIZE OF SPECARRAY AS NEEDED TO NUMBER OF YOUR SPEC VARIABLES PLUS 5;
    *;
    ARRAY SPECARRAY (*) B1-B4 B99SP D1-D5 D99SP E99SP F99SP G1-G3 H1 H99SP
        DISCDEP--OTHSTORE
        ;
    DO COUNT=1 TO DIM(SPECARRAY);
        IF SPECARRAY(COUNT)=. THEN DELETE;
    END;
%MEND;

LIBNAME IN "&CWD\DATA";
LIBNAME OUT "&CWD\DATA";

FILENAME OUTLOGS "&CWD\OUTPUT\LOGINDEXES.XLS";
FILENAME OUTCONTS "&CWD\OUTPUT\LOGCONTRIBS.XLS";
FILENAME OUTDISCS "&CWD\OUTPUT\DISCOUNTS.XLS";
FILENAME OUTPCTLS "&CWD\OUTPUT\PCTLS.XLS";

%INCLUDE "&CWD\TABLESTOBUILD.SAS";